package com.igeek.shop.service.product;

import java.util.List;

import com.igeek.shop.dao.BaseDao;
import com.igeek.shop.entity.Product;

public class ProductServiceImp implements ProductService {
	private BaseDao<Product> dao = new BaseDao<Product>();

	@Override
	public Product edit(String pid) {

		String sql = "select * from product where pid =?";
		Object[] params = { pid };
		Object userByOne = dao.getUserByOne(sql, params, new Product());
		Product product = (Product) userByOne;
		return product;

	}
	
	
	@Override
	public List<Product> getProductList() {
		String sql = "select * from product";
		Object[] params = {};
		Object list = dao.getList(sql, params, new Product());
		List productList = (List) list;
		return productList;

	}

	@Override
	public void deleteProduct(String pid) {
		String sql = "delete from product where pid = ?";
		Object[] params = { pid };
		dao.update(sql, params);

	}

	@Override
	public void insertProduct(Product product) {
		// TODO Auto-generated method stub

		String sql = "insert into product values (?,?,?,?,?,?,?,?,?,?)";
		Object[] params = { product.getPid(), product.getPname(), product.getMarket_price(), product.getShop_price(),
				product.getPimage(), product.getPdate(), product.getIs_hot(), product.getPdesc(), product.getPflag(),
				product.getCid() };
		dao.update(sql, params);
	}

	

	@Override
	public void updateProduct(Product product) {
		
		
		String sql = "update product set pname = ?,market_price=?,shop_price=?,pimage=?,pdate=?,is_hot=?,pdesc=?,pflag=?,cid=? where pid=?";
		Object [] params = {product.getPname(),product.getMarket_price(),product.getShop_price(),product.getPimage(),product.getPdate(),product.getIs_hot(),product.getPdesc(),product.getPflag(),product.getCid(),product.getPid()};
        dao.update(sql, params);
        
		
	}

}
